package com.hsd.znsh.handler;

import com.hsd.znsh.enums.ResultEnum;
import com.hsd.znsh.exception.ZnshException;
import com.hsd.znsh.pojo.output.ResultVO;
import com.hsd.znsh.utils.ResultVOUtil;
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class HwbExceptionHandler {


    @ExceptionHandler(value = ZnshException.class)
    @ResponseBody
    public ResultVO handlerAuthorizeException(ZnshException exception) {
        return ResultVOUtil.error(exception);
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO handlerException(Exception exception) {
        exception.printStackTrace();
        return ResultVOUtil.error(ResultEnum.SERVER_ERROR);
    }

    @MessageExceptionHandler(value = Exception.class)
    @SendToUser("/queue/error")
    public ResultVO handlerMessageException(Exception exception) {
        exception.printStackTrace();
        return ResultVOUtil.error(ResultEnum.SERVER_ERROR);
    }
}
